import * as api from '../../service/api'
const state = {
	sendedNoticeList : {},
	platformbalance : {},
	balanceList : {},
}

const getters = {
	sendedNoticeList : state => state.sendedNoticeList,
	platformbalance : state => state.platformbalance,
	balanceList : state => state.balanceList,
}

const actions = {

	
	async getDashboardData ({ commit }, {  cb, err, ...p }) {
		let res1 = await api.go(p, api.profitStatistics);
		let res2 = await api.go(p, api.orderStatistics);
		//let res3 = await api.go(p, 'memberStatistics');

		// console.log('111111111111');
		// console.log(res1);
		// console.log(res2);
		if(res1.errcode === 0 && res2.errcode === 0){
			if(cb){
				cb({
					'profit' : res1.data,
					'order' : res2.data,
				});
			}
		}else{
			if(err){
				err(res1.errmsg + ' : ' + res2.errmsg);
			}
		}
	},




	async sendNotice ({ commit }, para) {
		let res = await api.sendNotice(
			para.msg1,
			para.msg2,
			para.msg3,
			para.msg4,
			para.msg5,
			para.type
		);
		console.log(res);
		if(res.errcode === 0){
			if(para.cb){
				para.cb(res.data);
			}
		}else{
			if(para.err){
				para.err(res.errmsg);
			}
		}
	},


	async getSendedNoticeList ({ commit }, para) {
		let res = await api.sendedNoticeList(
			para.pageNo,
			para.pageSize
		);
		console.log(res);
		if(res.errcode === 0){
			commit('setSendedNoticeList', res.data);
			para.cb(res.data);
		}
	},
}

const mutations = {
	setSendedNoticeList (state, obj) {
        state.sendedNoticeList = obj;
    },
    setPlatformbalance (state, obj) {
        state.platformbalance = obj;
    },
    setBalanceList (state, obj) {
        state.balanceList = obj;
    },
}

export default {
  state,
  getters,
  actions,
  mutations
}
